<template>
	<view class="withdraw-view">
		<view class="withdraw-top">
			<view class="withdraw-title">提现金额</view>
			<view class="input-box fx-center">
				<text class="main-basic-name">¥</text>
				<input type="digit" v-model="money" :placeholder="getPlacehold" @focus="focus=true"
					@blur="focus=false" />
			</view>
			<view class="withdraw-tip-text">可提现金额：¥{{balance}}（提现手续费费率{{fee}}） </view>
		</view>
		<view class="withdraw-type">
			<view class="withdraw-title">提现方式</view>
			<view class="fx-center-between withdraw-wx">
				<view class="fx-center">
					<image src="/static/wx_icon.png" mode="heightFix"></image>
					<view class="">提现至微信</view>
				</view>
				<radio :checked="radioCheck" color="#4078E5" />
			</view>
		</view>
		<view class="main-basic-btn">
			<van-button block color="#4078E5" :disabled="money<=0" @click="submit">立即提现</van-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				money: '',
				balance: 0, //可提现
				fee: '', //手续费
				pay_type: 1, //提现方式
				min_pay: 0,
				radioCheck: true,
				focus: false
			};
		},
		onShow() {
			this.getMyWallent()
		},
		computed: {
			getPlacehold() {
				return this.focus ? '' : '请输入提现金额，不低于' + this.min_pay
			}
		},
		methods: {
			// 获取我的钱包
			getMyWallent() {
				this.$api.requst(`/gwc/user/wallet`, {}).then((res) => {
					this.balance = res.data.balance
					this.min_pay = res.data.withdraw.min_pay
					this.fee = res.data.withdraw.fee
					this.pay_type = res.data.withdraw.pay_type
				})
			},
			// 申请提现
			submit() {
				// if (Number(this.money) < Number(this.min_pay)) {
				// 	this.$api.showError('提现金额不能低于' + this.min_pay)
				// 	return
				// }
				uni.showLoading({
					title: '数据提交中...'
				})
				uni.login({
					provider: 'weixin', //使用微信登录
					success: (loginRes) => {
						this.$api.requst(`/gwc/user/withdraws`, {
							pay_type: this.pay_type,
							rmb: this.money,
							acc_no: loginRes.code
						}, 'POST').then((res) => {
							uni.redirectTo({
								url: '/pages/mine/myWallent/result/result'
							})
						})
					}
				});


			}
		}
	}
</script>

<style lang="scss">
	.withdraw-view {
		min-height: 100vh;
		background-color: #fff;
		box-sizing: border-box;

		.withdraw-title {
			font-size: 26rpx;
			color: #8A8F99;
		}

		.withdraw-top {
			padding: 32rpx;

			.input-box {
				margin-top: 40rpx;
				padding-bottom: 38rpx;
				border-bottom: 2rpx solid #E2E2E2;

				input {
					font-weight: bold;
					font-size: 40rpx;
					margin-left: 16rpx;
				}
			}

			.withdraw-tip-text {
				margin-top: 32rpx;
				font-size: 26rpx;
				color: #5C5F66;
			}
		}

		.withdraw-type {
			padding: 24rpx 32rpx;
			border-top: 16rpx solid #F1F3F6;

			.withdraw-wx {
				font-size: 30rpx;
				color: #333333;
				margin-top: 24rpx;

				image {
					width: 48rpx;
					height: 48rpx;
					margin-right: 14rpx;
				}
			}
		}
	}
</style>